/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "CLOSURE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Closure.findAll", query = "SELECT c FROM Closure c"),
    @NamedQuery(name = "Closure.findByIdClosure", query = "SELECT c FROM Closure c WHERE c.closurePK.idClosure = :idClosure"),
    @NamedQuery(name = "Closure.findByIdWarehouse", query = "SELECT c FROM Closure c WHERE c.closurePK.idWarehouse = :idWarehouse"),
    @NamedQuery(name = "Closure.findByInitdate", query = "SELECT c FROM Closure c WHERE c.initdate = :initdate"),
    @NamedQuery(name = "Closure.findByEnddate", query = "SELECT c FROM Closure c WHERE c.enddate = :enddate")})
public class Closure implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ClosurePK closurePK;
    @Column(name = "INITDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date initdate;
    @Column(name = "ENDDATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date enddate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "closure", fetch = FetchType.LAZY)
    private List<Consolidated> consolidatedList;
    @JoinColumn(name = "ID_WAREHOUSE", referencedColumnName = "ID_WAREHOUSE", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Warehouse warehouse;

    public Closure() {
    }

    public Closure(ClosurePK closurePK) {
        this.closurePK = closurePK;
    }

    public Closure(BigInteger idClosure, BigInteger idWarehouse) {
        this.closurePK = new ClosurePK(idClosure, idWarehouse);
    }

    public ClosurePK getClosurePK() {
        return closurePK;
    }

    public void setClosurePK(ClosurePK closurePK) {
        this.closurePK = closurePK;
    }

    public Date getInitdate() {
        return initdate;
    }

    public void setInitdate(Date initdate) {
        this.initdate = initdate;
    }

    public Date getEnddate() {
        return enddate;
    }

    public void setEnddate(Date enddate) {
        this.enddate = enddate;
    }

    @XmlTransient
    public List<Consolidated> getConsolidatedList() {
        return consolidatedList;
    }

    public void setConsolidatedList(List<Consolidated> consolidatedList) {
        this.consolidatedList = consolidatedList;
    }

    public Warehouse getWarehouse() {
        return warehouse;
    }

    public void setWarehouse(Warehouse warehouse) {
        this.warehouse = warehouse;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (closurePK != null ? closurePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Closure)) {
            return false;
        }
        Closure other = (Closure) object;
        if ((this.closurePK == null && other.closurePK != null) || (this.closurePK != null && !this.closurePK.equals(other.closurePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Closure[ closurePK=" + closurePK + " ]";
    }
    
}
